﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHQGHN.DAL.Common;
using DHQGHN.DAL.DAO.Admin;
using DHQGHN.DAL.Models.Admin;

namespace DHQGHN.DAL.BO.Admin
{
    public class HhRelationshipBO : BaseBO
    {
        public const string FIELD_HH_RELATIONSHIP_ID = "HH_RELATIONSHIP_ID";
        public const string FIELD_NAME = "NAME";
        public const string FIELD_CODE = "CODE";
        public const string FIELD_DESCRIPTIONS = "DESCRIPTIONS";
        public const string FIELD_DELETED = "DELETED";
        public const string Field_RECORD_COUNT = "RecordCount";

        private String _connectionString;

        public HhRelationshipBO(string connString)
        {
            this._connectionString = connString;

        }
        public HhRelationshipBO()
        {
            this._connectionString = Common.ConnectionUtil.TKTHDS_METADATA_CONNECTION_STRING;

        }

        public HhRelationshipDAO _hh_relationshipDAO;

        public HhRelationshipDAO CreateSQLDAO()
        {
            return new HhRelationshipDAO(_connectionString, DEFAULT_MAPPER_TYPE);
        }

        public DataPage<HhRelationshipModel> GetDynamicListPaging(HhRelationshipModel hModel, int pageSize, int pageIndex)
        {
            try
            {
                _hh_relationshipDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {HhRelationshipModel.FIELD_HH_RELATIONSHIP_ID,FIELD_HH_RELATIONSHIP_ID},
                    {HhRelationshipModel.FIELD_NAME,FIELD_NAME},
                    {HhRelationshipModel.FIELD_CODE,FIELD_CODE},  
                    {HhRelationshipModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {HhRelationshipModel.FIELD_DELETED,FIELD_DELETED},                    
                    {HhRelationshipModel.FIELD_RECORD_COUNT,Field_RECORD_COUNT}
                    
                };
                return _hh_relationshipDAO.GetDynamicListPaging(hModel, pageSize, pageIndex, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public HhRelationshipModel GetHhById(int? hh_relationship_Id)
        {
            try
            {
                _hh_relationshipDAO = CreateSQLDAO();

                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {HhRelationshipModel.FIELD_HH_RELATIONSHIP_ID,FIELD_HH_RELATIONSHIP_ID},
                    {HhRelationshipModel.FIELD_NAME,FIELD_NAME},
                    {HhRelationshipModel.FIELD_CODE,FIELD_CODE},  
                    {HhRelationshipModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {HhRelationshipModel.FIELD_DELETED,FIELD_DELETED}
                    
                };

                return _hh_relationshipDAO.GetById(hh_relationship_Id, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool createOrUpdateHh_relationship(HhRelationshipModel hhModel)
        {
            try
            {
                _hh_relationshipDAO = CreateSQLDAO();
                return _hh_relationshipDAO.createOrUpdateHh_relationship(hhModel);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public bool deleteHh_relationship(int hh_relationship_Id)
        {
            try
            {
                _hh_relationshipDAO = CreateSQLDAO();
                return _hh_relationshipDAO.deleteHh_relationship(hh_relationship_Id);
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}
